import os

# 读取Java文件内容
def read_file(file_path):
    with open(file_path, 'r', encoding='utf-8') as file:
        return file.readlines()

# TODO 主要修改的内容
# 处理Java文件内容
def process_file_content(lines):
    new_lines = []
    is_annot = False
    for line in lines:
        # 删除特定的注释行
        if "//C# TO JAVA CONVERTER TODO TASK: Java annotations will not correspond to .NET attributes:" in line:
            continue

        if "//C# TO JAVA CONVERTER TODO TASK: There is no preprocessor in Java:" in line:
            continue
       
        if "ORIGINAL LINE: [Serializable]" in line:
            continue

        # 如果是在注释内，进行处理
        if is_annot:
            if "*/" in line:
                is_annot = False
            elif len(line.strip()) ==0:
                continue
            else:
                line = '* ' + line
        if "/**" in line:
            is_annot = True

        new_lines.append(line)

    return new_lines

# 写入处理后的内容到新文件
def write_to_new_file(new_lines, output_file_path):
    with open(output_file_path, 'w', encoding='utf-8') as file:
        file.writelines(new_lines)

def deal_one(input_file_path):
    '''处理单个文件'''
    # 读取文件内容
    lines = read_file(input_file_path)
    # 处理文件内容
    new_lines = process_file_content(lines)
    # 写入新文件
    write_to_new_file(new_lines, input_file_path)

def filter_file(filename):
    '''过滤文件'''
    if filename.endswith('.ts') or filename.endswith('.vue') or filename.endswith('.js'):
        return True
    else:
        return False

in_dir = 'class'
if __name__ == "__main__":
    # 获取当前工作目录
    current_directory = os.getcwd()
    inpath = os.path.join(current_directory, in_dir)

    # 使用os.walk遍历当前目录
    for dirpath, dirnames, filenames in os.walk(inpath):
        # 打印当前遍历到的目录路径
        print(f"遍历到的目录: {dirpath}")

        for filename in filenames:
            if filter_file(filename):
                filepath = os.path.join(dirpath, filename)
                deal_one(filepath)
                print(f"处理完成文件：{filename}")
            else:
                print(f"跳过文件：{filename}")
        print(f'-' * 40)
